<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\common\model\AppInfo;

class Dowload extends Frontend
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function __construct()
    {
        echo 45;die;
    }

    public function index(){

        $ua = $_SERVER['HTTP_USER_AGENT'];
        if (strpos($ua, 'MicroMessenger') == false && strpos($ua, 'Windows Phone') == false) {
            $app_id=request()->get('app_id');
            $app=(new AppInfo())->find($app_id);
            if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
                echo 2;die;
                header('location:'.$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].$app->app_url);
            }else{
                echo 11;die;
                header('location:'.$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].$app->ios_url);
            }
        } else {
            echo '请用浏览器扫码';

        }
//        if(file_exists(__DIR__.'/'.$dir.$filename)){$_SERVER['REQUEST_SCHEME']."://".$_SERVER['SERVER_NAME'].$row->app_url

//        }else{
//            header('HTTP/1.1 404 Not Found');
//        }
    }
}
